﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.ComponentModel;
using System.Xml.Linq;
using Android.App;

namespace AndroidApp
{
    public class ViewManager
    {
        private object sync = new object();
        public List<Activity> ActivityList = new List<Activity>();

        public void RegisterActivity(Activity activity)
        {
            lock (sync)
            {
                if (!this.ActivityList.Contains(activity))
                    this.ActivityList.Add(activity);
            }
        }

        public void UnRegisterActivity(Activity activity)
        {
            lock (sync)
            {
                if (this.ActivityList.Contains(activity))
                    this.ActivityList.Remove(activity);
            }
        }

       
        public FirstView FirstView
        {
            get
            {
                var firstView = this.ActivityList.OfType<FirstView>().FirstOrDefault();
                if (firstView == null)
                    throw new ApplicationException("FirstView已经退出");
                return firstView;
            }
        }

        public AppOptionView AppOptionView
        {
            get
            {
                var view = this.ActivityList.OfType<AppOptionView>().FirstOrDefault();
                if (view == null)
                    throw new ApplicationException("AppOptionView已经退出");
                return view;
            }
        }

        public UploadView UploadView
        {
            get
            {
                var home = this.ActivityList.OfType<UploadView>().FirstOrDefault();
                if (home == null)
                    throw new ApplicationException("Home已经退出");
                return home;
            }
        }


        public DownloadView DownloadView
        {
            get
            {
                var view = this.ActivityList.OfType<DownloadView>().FirstOrDefault();
                return view;
            }
        }

        public void Close()
        {
            for (int i = this.ActivityList.Count - 1; i >= 0; i--)
            {
                this.ActivityList[i].Finish();
            }
        }

    }
}
